package app.tasks.schedule;

import app.env.Data;
import app.agent.Schedule;
import app.util.AppUtils;
import jade.core.AID;
import jade.core.behaviours.OneShotBehaviour;
import jade.lang.acl.ACLMessage;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

/**
 * @Name: StopSearch
 * @Description:
 * @Author: colfish
 * @Date: 2021/4/29 9:50
 * 好好学习，天天向上！
 */
public class StopSearch extends OneShotBehaviour {
    private static final long serialVersionUID = 6285904824993854344L;
    private Schedule schedule;
    private Logger logger = LogManager.getLogger(this.getClass());

    int nextState;

    public StopSearch(Schedule schedule){
        nextState = 1;
        this.schedule = schedule;
    }
    @Override
    public void action() {
        ACLMessage message = new ACLMessage(ACLMessage.INFORM);
        message.setContent(Data.SEARCH_STOP);
        for(String name : Data.searchSignals.keySet()){
            AID receiver = new AID(name, AID.ISLOCALNAME);
            message.addReceiver(receiver);
            schedule.send(message);
            logger.info(AppUtils.logMessage(schedule.getAID(), receiver, message));
        }
    }
}
